import { View } from "../../../../mvc/core/View";
import { MemberListPanel } from "./MemberListPanel";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { SystemSetter } from "../../system/SystemSetter";
import { Cache } from "../../../cache/Cache";
import { EGuildPosition } from "../../../../../Message/Game/EGuildPosition";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { GuildEventName } from "../GuildEventName";
import { MsgManager } from "../../../manager/MsgManager";
import { EventName } from "../../../mvc/EventName";
import { GameMapUtil } from "../../../scene/map/GameMapUtil";
import { ThingUtil } from "../../../scene/layer/utils/ThingUtil";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GCheckBox } from "../../../../../com/mui/controls/GCheckBox";
//class MemberManagerPanel
    
    export  class MemberManagerPanel extends View
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._memberListPanel = new MemberListPanel();
            this.addChild(this._memberListPanel);
            this._viewApplyBtn = ObjCreate.createGButton(Language.getString(57216), 10, 368, 70, 24, this);
            this._viewApplyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onViewApplyBtnClickHandler);
            this._showTitleCheckbox = ObjCreate.createCheckBox(Language.getString(57217), 130, 345, 200, 28, this);
            this._showTitleCheckbox.addEventListener(flash.events.MouseEvent.CLICK, this.onShowTitleCheckboxClickHandler);
            this._showTitleCheckbox.selected = SystemSetter.currentSetter.showGuildPost;
            this._onlineCheckbox = ObjCreate.createCheckBox(Language.getString(57218), 130, 370, 200, 28, this);
            this._onlineCheckbox.addEventListener(flash.events.MouseEvent.CLICK, this.onOnlineCheckboxClickHandler);
            this._nominateBtn = ObjCreate.createGButton(Language.getString(57219), 525, 368, 57, 24, this);
            this._nominateBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onNominateBtnClickHandler);
            this._kickBtn = ObjCreate.createGButton(Language.getString(57220), 590, 368, 57, 24, this);
            this._kickBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onKickBtnClickHandler);
            this.updateRight();
            return;
        }

        public updateRight(): void
        {
            var loc1=Cache.instance.guild.myGuildInfo;
            if (loc1 && (loc1.position == EGuildPosition._EGuildLeader || loc1.position == EGuildPosition._EGuildDeputyLeader || loc1.position == EGuildPosition._EGuildPresbyter)) 
            {
                this._viewApplyBtn.visible = true;
                this._nominateBtn.visible = true;
                this._kickBtn.visible = true;
            }
            else 
            {
                this._viewApplyBtn.visible = false;
                this._nominateBtn.visible = false;
                this._kickBtn.visible = false;
            }
            return;
        }

        public get memberListPanel(): MemberListPanel
        {
            return this._memberListPanel;
        }

        /* internal  */onViewApplyBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(GuildEventName.OpenGuildApplyListWindow));
            return;
        }

        /* internal  */onNominateBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=Cache.instance.guild.curSelGuildPlayer;
            if (loc1 == null) 
            {
                MsgManager.showRollTipsMsg(Language.getString(57221));
                return;
            }
            if (Cache.instance.guild.isLeader()) 
            {
                Dispatcher.dispatchEvent(new DataEvent(GuildEventName.OpenGuildNominateWindow));
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(57222));
            }
            return;
        }

        /* internal  */onKickBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=Cache.instance.guild.curSelGuildPlayer;
            if (loc1 == null) 
            {
                MsgManager.showRollTipsMsg(Language.getString(57223));
                return;
            }
            if (Cache.instance.guild.isLeader()) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildKickOut, Cache.instance.guild.curSelGuildPlayer));
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(57224));
            }
            return;
        }

        /* internal  */onShowTitleCheckboxClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=this._showTitleCheckbox.selected;
            SystemSetter.localSetter.setSystemInfo("showGuildPost", loc1);
            Dispatcher.dispatchEvent(new DataEvent(EventName.SaveForSliderChange));
            if (!GameMapUtil.isShowGuildNameMap()) 
            {
                ThingUtil.entityUtil.showUserGuildName(loc1);
            }
            return;
        }

        /* internal  */onOnlineCheckboxClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=this._onlineCheckbox.selected;
            this._memberListPanel.isOnlyOnline = loc1;
            if (loc1) 
            {
                this._memberListPanel.pageBar.currentPage = 1;
            }
            Dispatcher.dispatchEvent(new DataEvent(GuildEventName.SortMember, {"sortType": Cache.instance.guild.memSortType, "isOnlyOnline": loc1}));
            return;
        }

        /* internal */ /* var */_memberListPanel: MemberListPanel;

        /* internal */ /* var */_viewApplyBtn: GButton;

        /* internal */ /* var */_showTitleCheckbox: GCheckBox;

        /* internal */ /* var */_onlineCheckbox: GCheckBox;

        /* internal */ /* var */_nominateBtn: GButton;

        /* internal */ /* var */_kickBtn: GButton;
    }
